package cn.iocoder.yudao.module.trade.controller.admin.depositorderlackbottlesrelation;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.trade.controller.admin.depositorderlackbottlesrelation.vo.*;
import cn.iocoder.yudao.module.trade.dal.dataobject.depositorderlackbottlesrelation.DepositOrderLackBottlesRelationDO;
import cn.iocoder.yudao.module.trade.service.depositorderlackbottlesrelation.DepositOrderLackBottlesRelationService;

@Tag(name = "管理后台 - 欠瓶记录对应瓶数据")
@RestController
@RequestMapping("/trade/lack-bottles-relation")
@Validated
public class DepositOrderLackBottlesRelationController {

    @Resource
    private DepositOrderLackBottlesRelationService depositOrderLackBottlesRelationService;

    @PostMapping("/create")
    @Operation(summary = "创建欠瓶记录对应瓶数据")
    @PreAuthorize("@ss.hasPermission('trade:deposit-order-lack-bottles-relation:create')")
    public CommonResult<Long> createDepositOrderLackBottlesRelation(@Valid @RequestBody DepositOrderLackBottlesRelationSaveReqVO createReqVO) {
        return success(depositOrderLackBottlesRelationService.createDepositOrderLackBottlesRelation(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新欠瓶记录对应瓶数据")
    @PreAuthorize("@ss.hasPermission('trade:deposit-order-lack-bottles-relation:update')")
    public CommonResult<Boolean> updateDepositOrderLackBottlesRelation(@Valid @RequestBody DepositOrderLackBottlesRelationSaveReqVO updateReqVO) {
        depositOrderLackBottlesRelationService.updateDepositOrderLackBottlesRelation(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除欠瓶记录对应瓶数据")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('trade:deposit-order-lack-bottles-relation:delete')")
    public CommonResult<Boolean> deleteDepositOrderLackBottlesRelation(@RequestParam("id") Long id) {
        depositOrderLackBottlesRelationService.deleteDepositOrderLackBottlesRelation(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得欠瓶记录对应瓶数据")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('trade:deposit-order-lack-bottles-relation:query')")
    public CommonResult<DepositOrderLackBottlesRelationRespVO> getDepositOrderLackBottlesRelation(@RequestParam("id") Long id) {
        DepositOrderLackBottlesRelationDO depositOrderLackBottlesRelation = depositOrderLackBottlesRelationService.getDepositOrderLackBottlesRelation(id);
        return success(BeanUtils.toBean(depositOrderLackBottlesRelation, DepositOrderLackBottlesRelationRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得欠瓶记录对应瓶数据分页")
    @PreAuthorize("@ss.hasPermission('trade:deposit-order-lack-bottles-relation:query')")
    public CommonResult<PageResult<DepositOrderLackBottlesRelationRespVO>> getDepositOrderLackBottlesRelationPage(@Valid DepositOrderLackBottlesRelationPageReqVO pageReqVO) {
        PageResult<DepositOrderLackBottlesRelationDO> pageResult = depositOrderLackBottlesRelationService.getDepositOrderLackBottlesRelationPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DepositOrderLackBottlesRelationRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出欠瓶记录对应瓶数据 Excel")
    @PreAuthorize("@ss.hasPermission('trade:deposit-order-lack-bottles-relation:export')")
    @OperateLog(type = EXPORT)
    public void exportDepositOrderLackBottlesRelationExcel(@Valid DepositOrderLackBottlesRelationPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DepositOrderLackBottlesRelationDO> list = depositOrderLackBottlesRelationService.getDepositOrderLackBottlesRelationPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "欠瓶记录对应瓶数据.xls", "数据", DepositOrderLackBottlesRelationRespVO.class,
                        BeanUtils.toBean(list, DepositOrderLackBottlesRelationRespVO.class));
    }

}